﻿'========================================================================
'功能:申請MVPN
'作者:andy
'日期:2011/6/10
'========================================================================
Imports System.Data
Imports com.auo.flower.remote
Partial Class WebForm_SysParam_Apply
    Inherits BasePage
    Protected FormKind As String = "AUO.FORM.439"
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            hiUID.Value = ActualUID
            hidbName.Value = dbName

            Dim uBBL As OAMS.BBL.UsersBBL = New OAMS.BBL.UsersBBL()
            Dim dt As DataTable = uBBL.GetUsers(hiUID.Value, hidbName.Value)
            txtApplicant.Text = dt.Rows(0)("UserID").ToString()
            txtApplyDate.Text = Date.Today.ToString("yyyy/MM/dd")
            txtApplyExt.Text = dt.Rows(0)("Ext_No").ToString()
            txtApplyName.Text = dt.Rows(0)("UserName").ToString()
            txtFiller.Text = dt.Rows(0)("UserID").ToString()
            txtFillerExt.Text = dt.Rows(0)("Ext_No").ToString()

            If txtApplyExt.Text.Length >= 4 Then
                txtShortCode.Text = txtApplyExt.Text.Substring(0, 2) + "6" + txtApplyExt.Text.Substring(3)
            End If
            GetData()
        End If
    End Sub

    Private Sub GetData()
        Dim appDao As Telecom.DAO.ApplyDAO = New Telecom.DAO.ApplyDAO(hidbName.Value)
        Dim dt As DataTable = appDao.GetDataByUID(hiUID.Value)
        If dt.Rows.Count = 0 Then
            Exit Sub
        End If
        If dt.Rows(0)("Applicant").ToString = "" Then
            Return
        End If
        txtFormNo.Text = dt.Rows(0)("FormNo").ToString
        txtApplicant.Text = dt.Rows(0)("Applicant").ToString
        txtApplyName.Text = dt.Rows(0)("ApplyName").ToString
        txtFiller.Text = dt.Rows(0)("Filler").ToString
        txtApplyExt.Text = dt.Rows(0)("ApplyExt").ToString
        txtFillerExt.Text = dt.Rows(0)("FillerExt").ToString
        txtApplyDate.Text = DateTime.Parse(dt.Rows(0)("ApplyDate").ToString).ToString("yyyy/MM/dd HH:mm:ss")
        ddlExtKind.SelectedValue = dt.Rows(0)("ExtKind").ToString
        ddlsuit_site.DataBind()
        ddlsuit_site.SelectedValue = dt.Rows(0)("ApplyFactoryID").ToString
        ddltype_code.DataBind()
        ddltype_code.Text = dt.Rows(0)("ApplyType").ToString
        ddlNetworkType.DataBind()
        ddlNetworkType.Text = dt.Rows(0)("NetworkType").ToString
        txtTelNo.Text = dt.Rows(0)("TelNo").ToString
        ddlApplyItem.DataBind()
        ddlApplyItem.SelectedValue = dt.Rows(0)("ApplyItem").ToString
        ddlDialType.DataBind()
        ddlDialType.SelectedValue = dt.Rows(0)("DialType").ToString
        txtIDNo.Text = dt.Rows(0)("IDNo").ToString
        txtIDNo2.Text = dt.Rows(0)("IDNo2").ToString
        txtIDNo3.Text = dt.Rows(0)("IDNo3").ToString
        txtFactoryName.Text = dt.Rows(0)("FactoryName").ToString
        txtName2.Text = dt.Rows(0)("Name2").ToString
        txtTelNo2.Text = dt.Rows(0)("TelNo2").ToString
        txtTelNo3.Text = dt.Rows(0)("TelNo3").ToString
        txtName3.Text = dt.Rows(0)("Name3").ToString
        txtApplyMemo.Text = dt.Rows(0)("ApplyMemo").ToString
        txtShortCode.Text = dt.Rows(0)("ShortCode").ToString
      
        If ddltype_code.SelectedValue = "1" Then
            trComanyData.Visible = False
            trComanyTitle.Visible = False
            trFamilyData.Visible = False
            trFamilyTitle.Visible = False
        End If
        If ddltype_code.SelectedValue = "2" Then
            trComanyData.Visible = False
            trComanyTitle.Visible = False
            trFamilyData.Visible = True
            trFamilyTitle.Visible = True
        End If
        If ddltype_code.SelectedValue = "3" Then
            trComanyData.Visible = True
            trComanyTitle.Visible = True
            trFamilyData.Visible = False
            trFamilyTitle.Visible = False
        End If
        If ddltype_code.SelectedValue = "4" Then
            trComanyData.Visible = False
            trComanyTitle.Visible = False
            trFamilyData.Visible = False
            trFamilyTitle.Visible = False
        End If
        If ddltype_code.SelectedValue.Trim = "" Then
            trComanyData.Visible = False
            trComanyTitle.Visible = False
            trFamilyData.Visible = False
            trFamilyTitle.Visible = False
        End If
    End Sub

  

   
    Protected Sub ddltype_code_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddltype_code.DataBound
        ddltype_code.Items.Insert(0, "")
    End Sub

    Protected Sub ddltype_code_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddltype_code.SelectedIndexChanged
        OtherTelNo1.Visible = False


        If ddltype_code.SelectedValue = "1" Then
            trComanyData.Visible = False
            trComanyTitle.Visible = False
            trFamilyData.Visible = False
            trFamilyTitle.Visible = False
        End If
        If ddltype_code.SelectedValue = "2" Then
            trComanyData.Visible = False
            trComanyTitle.Visible = False
            trFamilyData.Visible = True
            trFamilyTitle.Visible = True
        End If
        If ddltype_code.SelectedValue = "3" Then
            trComanyData.Visible = True
            trComanyTitle.Visible = True
            trFamilyData.Visible = False
            trFamilyTitle.Visible = False
        End If
        If ddltype_code.SelectedValue = "4" Then
            trComanyData.Visible = False
            trComanyTitle.Visible = False
            trFamilyData.Visible = False
            trFamilyTitle.Visible = False
        End If
        If ddltype_code.SelectedValue.Trim = "" Then
            trComanyData.Visible = False
            trComanyTitle.Visible = False
            trFamilyData.Visible = False
            trFamilyTitle.Visible = False
        End If
        Dim bbl As Telecom.BBL.TelTypeBBL = New Telecom.BBL.TelTypeBBL()
        Dim dt As DataTable = bbl.GetTypeCode(ddlsuit_site.SelectedValue, ddltype_code.SelectedValue, hidbName.Value)
        If (dt.Rows.Count > 0) Then
            If dt.Rows(0)("Message").ToString.Trim <> "" Then
                ShowMessageForAjax(btnSave, dt.Rows(0)("Message").ToString)
            End If
            If dt.Rows(0)("NeedExt").ToString = "True" Then
                If ddlExtKind.SelectedValue = "" Then
                    ShowMessageForAjax(btnSave, GetLocalResourceObject("EmptyExtKind"))

                    Exit Sub
                End If

            Else

            End If
            If dt.Rows(0)("OnSiteFill").ToString = "True" Then
                txtShortCode.ReadOnly = True
            Else
                txtShortCode.ReadOnly = False
            End If
        End If

       

    End Sub

    Protected Sub ddlNetworkType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlNetworkType.SelectedIndexChanged

        'Dim bbl As Telecom.BBL.NetWorkTypeBBL 
        Dim dao As Telecom.DAO.NetworkTypeDAO = New Telecom.DAO.NetworkTypeDAO(hidbName.Value)
        Dim dt As DataTable = dao.GetDataBynetwork_no(ddlNetworkType.SelectedValue, ddlsuit_site.SelectedValue)
        If dt.Rows.Count > 0 Then
            If dt.Rows(0)("Message").ToString.Trim <> "" Then
                ShowMessageForAjax(btnSave, dt.Rows(0)("Message").ToString)
            End If
            
        End If

    End Sub

    Protected Sub ddlNetworkType_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlNetworkType.DataBound
        ddlNetworkType.Items.Insert(0, "")
    End Sub

    Protected Sub ddlApplyKind_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlApplyItem.DataBound
        ddlApplyItem.Items.Insert(0, "")
    End Sub

    Protected Sub ddlApplyKind_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlApplyItem.SelectedIndexChanged
        OtherTelNo1.Visible = False
        Dim bbl As Telecom.BBL.ApplyKindBBL = New Telecom.BBL.ApplyKindBBL()
        Dim dt As DataTable = bbl.GetApplyKindByTypeCode(ddlsuit_site.SelectedValue, ddlApplyItem.SelectedValue, hidbName.Value)
        If dt.Rows.Count > 0 Then
            If dt.Rows(0)("WarnMessage").ToString.Trim <> "" Then
                ShowMessageForAjax(btnSave, dt.Rows(0)("WarnMessage").ToString)
            End If
        End If
        'Dim dao As Telecom.DAO.ModifyItemDAO = New Telecom.DAO.ModifyItemDAO(hidbName.Value)
        'dt = dao.GetMODIFYItemKindByKindCode(ddlsuit_site.SelectedValue, ddlApplyItem.SelectedValue, "1")
        'ddlDialType.DataBind()
        'ddlDialType.Items.Insert(0, New ListItem("", ""))

    End Sub

    Protected Sub btnOthNo1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOthNo1.Click

        btnSave_Click(Nothing, Nothing)
        OtherTelNo1.Visible = True
        OtherTelNo1.InitDataAndShow(Integer.Parse(txtFormNo.Text), ddltype_code.SelectedValue)
    End Sub

   

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim appDao As Telecom.DAO.ApplyDAO = New Telecom.DAO.ApplyDAO(hidbName.Value)
        If (txtFormNo.Text = "") Then
            txtFormNo.Text = (appDao.InsertData())


        End If
        appDao.UpdateData(Integer.Parse(txtFormNo.Text), txtApplicant.Text, txtFiller.Text, txtApplyExt.Text, txtFillerExt.Text, ddlExtKind.SelectedValue, ddlsuit_site.SelectedValue, ddltype_code.SelectedValue, ddlNetworkType.SelectedValue, txtTelNo.Text, ddlApplyItem.SelectedValue, ddlDialType.SelectedValue, txtFactoryName.Text, txtName2.Text, txtTelNo2.Text, "0", txtTelNo3.Text, txtName3.Text, txtApplyMemo.Text, txtShortCode.Text, txtIDNo.Text, txtIDNo2.Text, txtIDNo3.Text)

    End Sub

    Protected Sub ddlsuit_site_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlsuit_site.DataBound
        ddlsuit_site.Items.Insert(0, New ListItem(""))
    End Sub

    Protected Sub ddlDialType_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlDialType.DataBound
        ddlDialType.Items.Insert(0, "")
    End Sub

    Private Function ChkData() As Boolean
        If ddlsuit_site.SelectedValue = "" Then
            ShowMessageForAjax(btnSend, GetLocalResourceObject("EmptySite"))
            Return False
        End If
        If ddlApplyItem.SelectedValue = "" Then
            ShowMessageForAjax(btnSend, GetLocalResourceObject("EmptyApplyItem"))
            Return False
        End If
        If ddlNetworkType.SelectedValue = "" Then
            ShowMessageForAjax(btnSend, GetLocalResourceObject("EmptyNetwokType"))
            Return False
        End If
        If ddlDialType.SelectedValue = "" Then
            ShowMessageForAjax(btnSend, GetLocalResourceObject("EmptyDialType"))
            Return False
        End If

        Dim dao As Telecom.DAO.NetworkTypeDAO = New Telecom.DAO.NetworkTypeDAO(hidbName.Value)
        Dim dt As DataTable = dao.GetDataBynetwork_no(ddlNetworkType.SelectedValue, ddlsuit_site.SelectedValue)
        'If dt.Rows.Count > 0 Then
        '    If dt.Rows(0)("Message").ToString.Trim <> "" Then
        '        ShowMessageForAjax(btnSave, dt.Rows(0)("Message").ToString)
        '    End If


        'End If

        If ddlExtKind.SelectedValue = "2" Then
            If txtShortCode.Text.Length = 0 Then
                ShowMessageForAjax(btnSave, GetLocalResourceObject("EmptyPNPCode"))
                Return False
            End If
        End If


        Dim bbl As Telecom.BBL.TelTypeBBL = New Telecom.BBL.TelTypeBBL()
        Dim dt1 As DataTable = bbl.GetTypeCode(ddlsuit_site.SelectedValue, ddltype_code.SelectedValue, hidbName.Value)
        If (dt1.Rows.Count > 0) Then
           
            If dt1.Rows(0)("NeedExt").ToString = "True" Then
                If ddlExtKind.SelectedValue = "" Then
                    ShowMessageForAjax(btnSave, GetLocalResourceObject("EmptyExtKind"))

                    Exit Function
                End If

            Else

            End If
           
        End If




        ''檢查有無輸入電話
        If txtTelNo.Text <> "" Then
            Return True
        End If

        If trComanyData.Visible Then
            If txtTelNo2.Text <> "" Then
                Return True
            End If
        End If

        If trFamilyData.Visible Then
            If txtTelNo3.Text <> "" Then
                Return True
            End If
        End If

        Dim dtOtherNo As DataTable
        Dim appDao As Telecom.DAO.ApplyDAO = New Telecom.DAO.ApplyDAO(hidbName.Value)

        dtOtherNo = appDao.GetDetail(txtFormNo.Text, "0")

        If dtOtherNo.Rows.Count > 0 Then
            Return True
        End If



        ShowMessageForAjax(btnSave, GetLocalResourceObject("EmptyTelNo"))
        Return False
    End Function

    Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click

        ' '' Save Data
        'btnSave_Click(Nothing, Nothing)
        ''檢查PHS轉MVPN'' 
        If ChkData() = False Then

            Return
        End If
        Dim networkBBL As Telecom.BBL.NetWorkTypeBBL = New Telecom.BBL.NetWorkTypeBBL()
        '檢查有無PHS資料,若為PHS轉MVPN時
        'If networkBBL.GetDataBynetwork_no(ddlNetworkType.SelectedValue, ddlsuit_site.SelectedValue, hidbName.Value).Rows(0)("ChkOA").ToString.ToLower = "true" Then

        '    ShowMessageForAjax(btnSave, GetLocalResourceObject("EmptyOAData"))
        '    Return
        'End If

        Dim ApproveLevel As Integer = 0
        Dim ApproveLeveltmp As Integer = 0
        Try

            Dim ChkOA As Boolean = networkBBL.GetDataBynetwork_no(ddlNetworkType.SelectedValue, ddlsuit_site.SelectedValue, hidbName.Value).Rows(0)("ChkOA")
            Dim phsBBl As Telecom.BBL.PHSBBL = New Telecom.BBL.PHSBBL()
            ''要檢查資產時才檢查,-->PHS轉MVPN
            If ChkOA Then
                If (phsBBl.ChkEmpNoPHS(txtApplicant.Text, "PHS") = False) Then
                    ShowMessageForAjax(btnSave, GetLocalResourceObject("EmptyOAData"))
                    Return
                End If
            End If
            ''檢查要送往的層級

            Dim typeBBl As Telecom.BBL.TelTypeBBL = New Telecom.BBL.TelTypeBBL() ''申請類別
            ApproveLeveltmp = Integer.Parse(typeBBl.GetTypeCode(ddlsuit_site.SelectedValue, ddltype_code.SelectedValue, hidbName.Value).Rows(0)("NeedApprove").ToString)
            If ApproveLevel < ApproveLeveltmp Then
                ApproveLevel = ApproveLeveltmp
            End If
            '入網類型
            ApproveLeveltmp = Integer.Parse(networkBBL.GetDataBynetwork_no(ddlNetworkType.SelectedValue, ddlsuit_site.SelectedValue, hidbName.Value).Rows(0)("NeedApprove").ToString)
            If ApproveLevel < ApproveLeveltmp Then
                ApproveLevel = ApproveLeveltmp
            End If
            ''申請項目
            Dim appKindBBL As Telecom.BBL.ApplyKindBBL = New Telecom.BBL.ApplyKindBBL()
            ApproveLeveltmp = Integer.Parse(appKindBBL.GetKind_code(ddlsuit_site.SelectedValue, ddlApplyItem.SelectedValue, hidbName.Value).Rows(0)("NeedApprove").ToString)
            If ApproveLevel < ApproveLeveltmp Then
                ApproveLevel = ApproveLeveltmp
            End If
            ''限撥權限
            Dim modiBBl As Telecom.BBL.ModifyItemBLL = New Telecom.BBL.ModifyItemBLL
            ApproveLeveltmp = Integer.Parse(modiBBl.GetModifyItem_Data(ddlsuit_site.SelectedValue, ddlDialType.SelectedValue, hidbName.Value).Rows(0)("NeedApprove").ToString)
            If ApproveLevel < ApproveLeveltmp Then
                ApproveLevel = ApproveLeveltmp
            End If
        Catch ex As Exception
            ShowMessageForAjax(btnSend, ex.Message)
            Return
        End Try

        Dim appDao As Telecom.DAO.ApplyDAO = New Telecom.DAO.ApplyDAO(hidbName.Value)
        If (txtFormNo.Text = "") Then
            txtFormNo.Text = (appDao.InsertData())


        End If
        appDao.UpdateData(Integer.Parse(txtFormNo.Text), txtApplicant.Text, txtFiller.Text, txtApplyExt.Text, txtFillerExt.Text, ddlExtKind.SelectedValue, ddlsuit_site.SelectedValue, ddltype_code.SelectedValue, ddlNetworkType.SelectedValue, txtTelNo.Text, ddlApplyItem.SelectedValue, ddlDialType.SelectedValue, txtFactoryName.Text, txtName2.Text, txtTelNo2.Text, "1", txtTelNo3.Text, txtName3.Text, txtApplyMemo.Text, txtShortCode.Text, txtIDNo.Text, txtIDNo2.Text, txtIDNo3.Text)
        ''UserType=個人/公司行號
        Dim uBBl As OAMS.BBL.UsersBBL = New OAMS.BBL.UsersBBL()
        Dim dt As DataTable = uBBl.GetUsers(txtApplicant.Text, hidbName.Value)
        Dim ApplicantName As String = ""
        Dim ApplicantLOGINID As String = ""
        Dim EmpName As String = ""
        Dim Username1 As String = ""
        Dim FirstPay As String = ""
        If dt.Rows.Count > 0 Then
            ApplicantName = dt.Rows(0)("UserName").ToString
            ApplicantLOGINID = dt.Rows(0)("login_id").ToString
        End If

        dt = uBBl.GetUsers(txtFiller.Text, hidbName.Value)
        If dt.Rows.Count > 0 Then
            EmpName = dt.Rows(0)("UserName").ToString

        End If
        Dim bblNetWork As Telecom.BBL.NetWorkTypeBBL = New Telecom.BBL.NetWorkTypeBBL()
        dt = bblNetWork.GetDataBynetwork_no(ddlNetworkType.SelectedValue, ddlsuit_site.SelectedValue, hidbName.Value)
        If dt.Rows.Count > 0 Then
            If dt.Rows(0)("FirstPay") = "True" Then
                FirstPay = "Y"
            Else
                FirstPay = "N"
            End If

        End If
        ''有申請門號'才加入CHTMVPN
        If txtTelNo.Text <> "" Then
            appDao.InsertChtMVPN(txtApplicant.Text, ApplicantName, ApplicantLOGINID, txtFiller.Text, EmpName, "個人", ApplicantName, txtTelNo.Text, txtIDNo.Text, ddlNetworkType.SelectedItem.Text, txtShortCode.Text, FirstPay, txtFormNo.Text)
        End If

        Dim dtOtherNo As DataTable
        dtOtherNo = appDao.GetDetail(txtFormNo.Text, "0")
        ''親友新增到 CHTMVPN
        If trFamilyData.Visible Then
            If txtTelNo3.Text <> "" Then
                appDao.InsertChtMVPN(txtApplicant.Text, ApplicantName, ApplicantLOGINID, txtFiller.Text, EmpName, "個人", txtName3.Text, txtTelNo3.Text, txtIDNo3.Text, ddlNetworkType.SelectedItem.Text, txtShortCode.Text, FirstPay, txtFormNo.Text)
            End If
            For Each dr As DataRow In dtOtherNo.Rows
                If dr("TelNo").ToString <> "" Then
                    appDao.InsertChtMVPN(txtApplicant.Text, ApplicantName, ApplicantLOGINID, txtFiller.Text, EmpName, "個人", dr("Name").ToString, dr("TelNo").ToString, dr("IDNo").ToString, ddlNetworkType.SelectedItem.Text, txtShortCode.Text, FirstPay, txtFormNo.Text)
                End If
            Next


        End If

        ''Company新增到 CHTMVPN
        If trComanyData.Visible Then
            If txtTelNo2.Text <> "" Then
                appDao.InsertChtMVPN(txtApplicant.Text, ApplicantName, ApplicantLOGINID, txtFiller.Text, EmpName, "公司行號", txtName2.Text, txtTelNo2.Text, txtIDNo2.Text, ddlNetworkType.SelectedItem.Text, txtShortCode.Text, FirstPay, txtFormNo.Text)
            End If
            For Each dr2 As DataRow In dtOtherNo.Rows
                If dr2("TelNo").ToString <> "" Then
                    appDao.InsertChtMVPN(txtApplicant.Text, ApplicantName, ApplicantLOGINID, txtFiller.Text, EmpName, "公司行號", dr2("Name").ToString, dr2("TelNo").ToString, dr2("IDNo").ToString, ddlNetworkType.SelectedItem.Text, txtShortCode.Text, FirstPay, txtFormNo.Text)
                End If
            Next
        End If



        If trComanyData.Visible = False And trFamilyData.Visible = False Then
            For Each dr3 As DataRow In dtOtherNo.Rows
                If dr3("TelNo").ToString <> "" Then
                    appDao.InsertChtMVPN(txtApplicant.Text, ApplicantName, ApplicantLOGINID, txtFiller.Text, EmpName, "個人", dr3("Name").ToString, dr3("TelNo").ToString, dr3("IDNo").ToString, ddlNetworkType.SelectedItem.Text, txtShortCode.Text, FirstPay, txtFormNo.Text)
                End If
            Next

        End If

        ''分機資料和HR的資料不一樣則加到分機資料中

        Dim dDao As Telecom.DAO.ExtNoDAO = New Telecom.DAO.ExtNoDAO(hidbName.Value)
        Dim dt3 As DataTable = uBBl.GetUsers(txtApplicant.Text, hidbName.Value)
        Dim dt2 As DataTable = dDao.GetDataByEmpNo(txtApplicant.Text, txtApplyExt.Text)
        If dt3.Rows.Count > 0 Then
            If dt3.Rows(0)("ext_no").ToString <> txtApplyExt.Text Then

                If dt2.Rows.Count = 0 Then
                    dDao.InsertMVPNExtNo(txtApplicant.Text, txtApplyExt.Text, hiUID.Value, Integer.Parse(txtFormNo.Text))
                End If


            End If
        End If


        '送往FlowER
        Dim formNo As Integer
        '' Dim formMVPN As MVPN.Manager.FromMVPNRemote = New MVPN.Manager.FromMVPNRemote(Me)
        Dim objhelper As IRemotingFlowHelper = DirectCast(RemotingHelperCreator.CreateInstance(GetType(IRemotingFlowHelper)), IRemotingFlowHelper)
        formNo = objhelper.CreateNewForm(FormKind, ActualUID)
        appDao.UpdateMVPNApproveFlowerFormNo(formNo.ToString, txtFormNo.Text)
        Dim objParas(2) As IParameter
        Dim dtOnSite As DataTable
        Dim oBBL As Telecom.BBL.OnSiteBBL = New Telecom.BBL.OnSiteBBL()
        dtOnSite = oBBL.GetOnSite("0", ddlsuit_site.SelectedValue, hidbName.Value)
        Dim IT_Approve As String = ""
        Dim OnSiteUID As String = ""
        If dtOnSite.Rows.Count > 0 Then
            IT_Approve = dtOnSite.Rows(0)("IT_Approve").ToString
            OnSiteUID = dtOnSite.Rows(0)("OnSiteUID").ToString
        End If
  
        objParas(0) = New para("Approve_Flag", ApproveLevel.ToString) ''層級
        objParas(1) = New para("Approve_IT", IT_Approve) 'IT必要簽核人員
        objParas(2) = New para("Approve_OA", OnSiteUID) '駐廠
     
        objhelper.AddFlag(FormKind, formNo, objParas)
        objhelper.SendForm(FormKind, formNo, ActualUID)
        objhelper.ActiveForm(FormKind, formNo)
        Response.Redirect(System.Configuration.ConfigurationManager.AppSettings("ApplyReturnPath"))
    End Sub

    Protected Sub ddlDialType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlDialType.SelectedIndexChanged
        Dim dao As Telecom.DAO.ModifyItemDAO = New Telecom.DAO.ModifyItemDAO(hidbName.Value)
        Dim dt As DataTable = dao.GetModifyItem_Data(ddlsuit_site.SelectedValue, ddlDialType.SelectedValue)
        If dt.Rows.Count > 0 Then
            If dt.Rows(0)("Message").ToString().Trim <> "" Then
                ShowMessageForAjax(btnSave, dt.Rows(0)("Message").ToString())
            End If
        End If
    End Sub

    Protected Sub txtApplyExt_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtApplyExt.TextChanged
        Dim uBBl As OAMS.BBL.UsersBBL = New OAMS.BBL.UsersBBL()
        Dim dDao As Telecom.DAO.ExtNoDAO = New Telecom.DAO.ExtNoDAO(hidbName.Value)
        Dim dt As DataTable = uBBl.GetUsers(txtApplicant.Text, hidbName.Value)
        Dim dt2 As DataTable = dDao.GetDataByEmpNo(txtApplicant.Text, txtApplyExt.Text)
        If dt.Rows.Count > 0 Then
            If dt.Rows(0)("ext_no").ToString <> txtApplyExt.Text Then

                If dt2.Rows.Count = 0 Then
                    ShowMessageForAjax(btnSave, GetLocalResourceObject("AddDataMsg"))
                End If


            End If
        End If

        If txtApplyExt.Text.Length >= 4 Then
            txtShortCode.Text = txtApplyExt.Text.Substring(0, 2) + "6" + txtApplyExt.Text.Substring(3)
        End If
    End Sub

    Protected Sub ddlExtKind_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlExtKind.SelectedIndexChanged
        If ddlExtKind.SelectedValue = "1" Then
            txtShortCode.ReadOnly = True
        Else
            txtShortCode.ReadOnly = False

        End If
    End Sub
End Class
